<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
	String blogId = request.getParameter("blogId") ;
	pageContext.setAttribute("blogId", blogId) ;
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<!-- 引入ueditor -->
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
<title>写博客</title>
<script type="text/javascript" language="JavaScript">
	

	$(function(){
		//实例化编辑器
		var ue = UE.getEditor('content');
		blogId = "${blogId}" ;
		if(blogId != null && blogId != "") {
			
			//需要加载ueditor中的内容必须使用ueditor所支持的方法
			
			ue.addListener("ready",function(){
				UE.ajax.request("${pageContext.request.contextPath}/admin/blog/minute.do",
						{
							method:'POST',
							//必须设置为同步
							async:false,
							data:{"blogId":blogId},
							onsuccess:function(data) {
								//原生 解析json
								data=eval("("+data.responseText+")");
								$("#title").val(data.data.title) ;
								$("#keyWord").val(data.data.keyWord) ;
								$("#typeId").combobox("setValue",data.data.blogType.typeId) ;
								UE.getEditor('content').setContent(data.data.content) ;
							}
						}) ;
			}) ;
			
		}
		$("#submitBtn").click(function(){
			var flag = vaildInfo() ;
			if(flag) {
				var title = $("#title").val() ;
				var typeId = $("#typeId").combobox("getValue") ;
				var content = UE.getEditor('content').getContent()
				var keyWord = $("#keyWord").val() ;
				var summary = UE.getEditor('content').getContentTxt().substr(0,155) ;
				var contentNoTag = UE.getEditor('content').getContentTxt() ;
				$.ajax({
					type:'POST',
					url:'${pageContext.request.contextPath}/admin/blog/update.do',
					data:{
						blogId:blogId,
						title:title,
						typeId:typeId,
						content:content,
						keyWord:keyWord,
						summary:summary,
						contentNoTag:contentNoTag
					},
					success:function(data) {
						$.messager.alert("系统提示",data.data) ;
						$("#title").val("") ;
						$("#typeId").combobox("setValue","") ;
						UE.getEditor('content').setContent('') ;
						$("#keyWord").val("") ;
					}
				}) ;
			}
		}) ;
	}) ;
	
	function vaildInfo() {
		var flag = true ;
		var title = $("#title").val() ;
		var typeId = $("#typeId").combobox("getValue") ;
		var content = UE.getEditor('content').getContent()
		var keyWord = $("#keyWord").val() ;
		
		if(title != null && title != "") {
			
		} else {
			$.messager.alert("系统提示","标题不能为空") ;
			flag = false ;
		}
		
		if(typeId != null && typeId != "") {
			
		} else {
			$.messager.alert("系统提示","请选择博客类型") ;
			flag = false ;
		}
		
		if(content != null && content != "") {
			
		} else {
			$.messager.alert("系统提示","博客内容不能为空") ;
			flag = false ;
		}
		
		if(flag) {
			return true ;
		} else {
			return false ;
		}
	}
</script>
</head>
<body style="margin: 10px;">

	<div id="p" class="easyui-panel" title="编写博客" style="padding: 10px;">
		<table>
			<tr>
				<td width="80">博客标题：</td>
				<td>
					<input type="text" name="title" id="title" style="width: 400px;" />
				</td>
			</tr>
			
			<tr>
				<td>所属类别：</td>
				<td>
					<select class="easyui-combobox" style="width: 154px;" id="typeId" name="typeId" editable="false" panelHeight="auto">
						<option value="">请选择博客类别...</option>
						<c:forEach items="${typeList }" var="blogType">
							<option value="${blogType.typeId }">${blogType.typeName }</option>
						</c:forEach>
					</select>
				</td>
			</tr>
			
			<tr>
				<td>博客内容：</td>
				<td>
					<!-- 加载编辑器的容器 -->
					<script id="content" name="content" type="text/plain" style="width:100%;height:500px;"></script>
				</td>
			</tr>
			
			<tr>
				<td>关键字：</td>
				<td>
					<input type="text" name="keyWord" id="keyWord" style="width: 400px;" />&nbsp;(多个关键字中间使用空格隔开)
				</td>
			</tr>
			
			<tr>
				<td></td>
				<td>
					<a href="javascript:void(0)" id="submitBtn" class="easyui-linkbutton" data-options="iconCls:'icon-submit'">发布博客</a>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>